//
//  CellForVideoList.m
//  世界
//
//  Created by admin on 16/2/14.
//  Copyright © 2016年 admin. All rights reserved.
//

#import "CellForVideoList.h"
#import "DataBaseForVideo.h"
#import "ModelForForVideoCollect.h"


@interface CellForVideoList ()

@property (nonatomic, retain) UIImageView *imgViewForPlay;
@property (nonatomic, retain) UIView *viewForSeparator;
@property (nonatomic, retain) UIImageView *imgViewForTime;
@property (nonatomic, retain) UIImageView *imgViewForPlayCount;
@property (nonatomic, retain) UIImageView *imgViewForReplyCount;
@property (nonatomic, retain) UIButton *buttonForShare;
@property (nonatomic, assign) BOOL isSelect;

@end

@implementation CellForVideoList



#pragma mark 重写dealloc方法
- (void)dealloc
{
    [_imgView release];
    
    [_viewForSeparator release];
    
    [_imgViewForTime release];
    
    [_lableForTimeLength release];
    
    [_lableForTitle release];
    
    [_lableForDescription release];
    
    [_imgViewForPlay release];
    
    [_imgViewForPlayCount release];
    
    [_lableForPlayCount release];
    
    [_lableForReplyCount release];
    
    [_imgViewForReplyCount release];
    
    [_buttonForShare release];
    
    [_buttonForCollect release];
    
    [super dealloc];
}

#pragma mark 重写初始化化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self != nil)
    {
        self.viewForSeparator = [[UIView alloc] init];
        
        [self.contentView addSubview:self.viewForSeparator];
        
        self.viewForSeparator.backgroundColor = [UIColor lightGrayColor];
        
        self.viewForSeparator.alpha = 0.4;
        
        self.viewForSeparator.layer.cornerRadius = 2.5;
        
        self.viewForSeparator.layer.masksToBounds = YES;
        
        [_viewForSeparator release];
        
        
        
        
        self.imgView = [[UIImageView alloc] init];
        
        [self.contentView addSubview:self.imgView];
                
        self.imgView.layer.masksToBounds = YES;
        
        self.imgView.layer.cornerRadius = 12;
        
        [_imgView release];
        
        
        
        
        self.lableForTitle = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.lableForTitle];
        
        //[self.lableForTitle setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
        
        [self.lableForTitle setFont:[UIFont systemFontOfSize:20]];
        
        [_lableForTitle release];
        
        
        
        
        self.lableForDescription = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.lableForDescription];
        
        self.lableForDescription.font = [UIFont systemFontOfSize:18];
        
        self.lableForDescription.textColor = [UIColor lightGrayColor];
        
        [_lableForDescription release];
        
        
        
        
        self.imgViewForPlay = [[UIImageView alloc] init];
        
        [self.imgView addSubview:self.imgViewForPlay];
        
        self.imgViewForPlay.image = [UIImage imageNamed:@"播放"];
        
        [_imgViewForPlay release];
        
        
        
        
        self.imgViewForTime = [[UIImageView alloc] init];
        
        [self.contentView addSubview:self.imgViewForTime];
        
        self.imgViewForTime.image = [UIImage imageNamed:@"时长"];
        
        [_imgViewForTime release];
        
        
        
        
        self.lableForTimeLength = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.lableForTimeLength];
        
        self.lableForTimeLength.textColor = [UIColor lightGrayColor];
        
        [_lableForTimeLength release];
        
        
        
        
        self.imgViewForPlayCount = [[UIImageView alloc] init];
        
        [self.contentView addSubview:self.imgViewForPlayCount];
        
        self.imgViewForPlayCount.image = [UIImage imageNamed:@"播放次数"];

        [_imgViewForPlayCount release];
        
        
        
        
        self.lableForPlayCount = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.lableForPlayCount];
        
        self.lableForPlayCount.textColor = [UIColor lightGrayColor];
        
        [_lableForPlayCount release];
        
        
        
        
        self.imgViewForReplyCount = [[UIImageView alloc] init];
        
        [self.contentView addSubview:self.imgViewForReplyCount];
        
        self.imgViewForReplyCount.image = [UIImage imageNamed:@"跟帖"];
        
        [_imgViewForReplyCount release];
        
        
        
        
        self.lableForReplyCount = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.lableForReplyCount];
        
        self.lableForReplyCount.textColor = [UIColor lightGrayColor];
        
        [_lableForReplyCount release];
        
        
        
        
        self.buttonForShare = [UIButton buttonWithType:UIButtonTypeSystem];
        
        [self.contentView addSubview:self.buttonForShare];
        
        [self.buttonForShare setBackgroundImage:[UIImage imageNamed:@"分享"] forState:UIControlStateNormal];
        
        [self.buttonForShare addTarget:self action:@selector(buttonForShareAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [_buttonForShare release];
        
        
        
        
        self.buttonForCollect = [UIButton buttonWithType:UIButtonTypeSystem];
        
        [self.contentView addSubview:self.buttonForCollect];
        
        [self.buttonForCollect addTarget:self action:@selector(buttonForCollectAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [_buttonForCollect release];
    }
    return self;
}

#pragma mark 点击分享BUtton所触发的方法
- (void)buttonForShareAction:(UIButton *)button
{
    NSLog(@"分享");
}



- (void)buttonForCollectAction:(UIButton *)button
{
    NSLog(@"收藏");
    
    NSLog(@"收藏的是第几行:%ld", self.number);
    
    [[DataBaseForVideo shareDataBaseHandle]open];
    
    [[DataBaseForVideo shareDataBaseHandle] createTable];
    
    ModelForForVideoCollect *model3 = self.arrForCollect[self.number];
    
    self.isSelect =  [[DataBaseForVideo shareDataBaseHandle]select:model3];
    
    if (self.isSelect)
    {
        [[DataBaseForVideo shareDataBaseHandle]deleteWithCode:model3.title];
        
        
        [self.buttonForCollect setBackgroundImage:[UIImage imageNamed:@"取消收藏"] forState:UIControlStateNormal];
        
        self.isSelect = NO;
    }
    else
    {
        
        [[DataBaseForVideo shareDataBaseHandle] insertCollect:self.arrForCollect[self.number]];
        
        [self.buttonForCollect setBackgroundImage:[UIImage imageNamed:@"收藏"] forState:UIControlStateNormal];
        
        self.isSelect = YES;
    }
    
}



#pragma mark 重写 布局子视图方法
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.viewForSeparator.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 5);
    
    self.lableForTitle.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 10, 25);
    
    self.lableForDescription.frame = CGRectMake(10, 10 + 25 + 5, self.contentView.frame.size.width - 10, 25);
    
    self.imgView.frame = CGRectMake(10, 10 + 25 + 5 + 25 + 5, self.contentView.frame.size.width - 20, 200);
    
    self.imgViewForPlay.frame = CGRectMake(207 - 30, 150 - 80, 50, 50);
    
    self.imgViewForTime.frame = CGRectMake(15, 10 + 25 + 5 + 25 + 5 + 200 + 10, 20, 20);
    
    self.lableForTimeLength.frame = CGRectMake(45, 10 + 25 + 5 + 25 + 5 + 200 + 10, 50, 20);
    
    self.imgViewForPlayCount.frame = CGRectMake(115, 10 + 25 + 5 + 25 + 5 + 200 + 10, 20, 20);

    self.lableForPlayCount.frame = CGRectMake(145, 10 + 25 + 5 + 25 + 5 + 200 + 10, 50, 20);
    
    self.imgViewForReplyCount.frame = CGRectMake(215, 10 + 25 + 5 + 25 + 5 + 200 + 10, 20, 20);
    
    self.lableForReplyCount.frame = CGRectMake(245, 10 + 25 + 5 + 25 + 5 + 200 + 10, 50, 20);
    
    self.buttonForShare.frame = CGRectMake(280, 10 + 25 + 5 + 25 + 5 + 200 + 5, 30, 30);
    
     self.buttonForCollect.frame = CGRectMake(340, 10 + 25 + 5 + 25 + 5 + 200 + 5, 30, 30);
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
